package com.GZX.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Course {
    private String cId;
    private int maxStudents;
    private List<String> eStudents;

    public String getcId() {
        return cId;
    }

    public void setcId(String courseId) {
        this.cId = courseId;
    }

    public int getMaxStudents() {
        return maxStudents;
    }

    public void setMaxStudents(int maxStudents) {
        this.maxStudents = maxStudents;
    }

    public Course(String courseId, int maxStudents) {
        this.cId = courseId;
        this.maxStudents = maxStudents;
        this.eStudents = new ArrayList<>();
    }

    public synchronized boolean enroll(String studentId) {
        if (eStudents.size() < maxStudents) {
            eStudents.add(studentId);
//            System.out.println(studentId + "----->选择课程: " + courseId);
            return true;
        } else {
            System.out.println(cId + " 已选满！");
            return false;
        }
    }
}



